package com.campus.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.campus.common.core.domain.AjaxResult;
import com.campus.pojos.domain.BillBoard;
import com.campus.pojos.domain.ClientCategory;
import com.campus.pojos.domain.dto.CategoryQueryDto;
import com.campus.result.PageResult;
import com.campus.result.Result;
import com.campus.service.BillboardService;
import com.campus.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController(value ="adminCategoryController")
@RequestMapping("/system/admin/category")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private BillboardService billboardService;
    @PostMapping("/list")
    public AjaxResult categoryList(@RequestBody CategoryQueryDto dto){
        return categoryService.getList(dto);
    }

    /**
     * 根据id查分类名称
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Integer id)
    {
        ClientCategory category = categoryService.getById(id);
        return AjaxResult.success("success",category);
    }


    /**
     * 管理端编辑墙
     * @param category
     * @return
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ClientCategory category)
    {
        categoryService.edit(category);
        return AjaxResult.success();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Integer id)
    {
        ClientCategory category = categoryService.getById(id);
        if(category == null) return AjaxResult.error("没有该id的墙分类");
        categoryService.removeById(id);
        return AjaxResult.success("success");
    }
}
